using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Temp.Database;
using Temp.Model;

namespace Temp.Controller
{
    class PeerController
    {
        private Random rand;
        private SQLiteFactory sqlf;
        private SQLite.SQLiteConnection conn;

        public PeerController()
        {
            rand = new Random();
            sqlf = new SQLiteFactory();
        }
        /// <summary>
        /// gets a dialogue
        /// </summary>
        /// <param name="goodOrBad">good -> 1 bad-> -1 neutral->0</param>
        /// <returns>returns a number dialogue</returns>
        public String getDialogue(int goodOrBad)
        {
            String str = "";
                
            if (goodOrBad != 0)
            {
                List<PeerDialogue> dialogues = new List<PeerDialogue>();
                String peer = "";
                conn = sqlf.getConnection();

                if (goodOrBad == 1)
                    peer = "good critic";
                if (goodOrBad == -1)
                    peer = "bad critic";

                dialogues = conn.Query<PeerDialogue>("SELECT * from Peer WHERE role='" + peer + "'").ToList();

                try
                {
                    str = dialogues[rand.Next(dialogues.Count)].dialogue;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error: No peer dialogue templates");
                }

                conn.Close();
            }
            else
                str = null;
            return str;
        }
    }
}
